package cn.wenhaha.app.config;

import cn.hutool.core.util.StrUtil;
import cn.wenhaha.common.config.GlobalApp;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 首次安装检测拦截器
 * --------
 *
 * @author ：wyndem
 * @Date ：Created in 2023-01-26 20:06
 */
public class InstallAppInterceptor implements HandlerInterceptor {

    private  Boolean install = false;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        String requestURI = request.getRequestURI();

        // 只有安装了才给放行
        if (StrUtil.equals(requestURI,"/install") || install || GlobalApp.isLoadConfigDb()){
            if (!install && GlobalApp.isLoadConfigDb()){
                install =true;
            }
            return true;
        }
        // 没有安装
        response.sendRedirect("/install");
        return false;
    }
}
